USE [Monitoring]
GO

--|--------------------------------------------------------------------------------
--| [GetTeamByID] - Insert Procedure Script for Team
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetTeamByID]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetTeamByID]
GO

CREATE PROCEDURE [dbo].[GetTeamByID]
(
	@ID int
)
AS
	SET NOCOUNT ON

	SELECT
		[ID],
		[Name],
		[Description]
	FROM 
Team
	WHERE
		[ID] = @ID
	
GO


--|--------------------------------------------------------------------------------
--| [InsertTeam] - Insert Procedure Script for Team
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[InsertTeam]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[InsertTeam]
GO

CREATE PROCEDURE [dbo].[InsertTeam]
(
	@ID int = NULL OUTPUT,
	@Name nvarchar(50),
	@Description nvarchar(250) = NULL
)
AS
	SET NOCOUNT ON

	INSERT INTO [Team]
	(
		[Name],
		[Description]
	)
	VALUES
	(
		@Name,
		@Description
	)

	SELECT @ID = SCOPE_IDENTITY();

	RETURN @@Error
GO

--|--------------------------------------------------------------------------------
--| [UpdateTeam] - Update Procedure Script for Team
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[UpdateTeam]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[UpdateTeam]
GO

CREATE PROCEDURE [dbo].[UpdateTeam]
(
	@ID int,
	@Name nvarchar(50),
	@Description nvarchar(250) = NULL
)
AS
	SET NOCOUNT ON
	
	UPDATE [Team]
	SET
		[Name] = @Name,
		[Description] = @Description
	WHERE 
		[ID] = @ID

	RETURN @@Error
GO

--|--------------------------------------------------------------------------------
--| [DeleteTeam] - Update Procedure Script for Team
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[DeleteTeam]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[DeleteTeam]
GO

CREATE PROCEDURE [dbo].[DeleteTeam]
(
	@ID int
)
AS
	SET NOCOUNT ON

	DELETE 
	FROM   [Team]
	WHERE  
		[ID] = @ID

	RETURN @@Error
GO

